package com.eqdd.yiqidian.kotlin

import android.support.v4.content.ContextCompat
import android.view.View
import com.eqdd.yiqidian.R
import com.eqdd.yiqidian.base.BaseActivity
import kotlinx.android.synthetic.main.activity_title.*
import org.jetbrains.anko.backgroundColor
import org.jetbrains.anko.sdk25.coroutines.onClick

/**
 * @author吕志豪 .
 * @date 18-3-21  下午5:03.
 * Github :https://github.com/lvzhihao100
 * E-Mail：1030753080@qq.com
 * 简书 :http://www.jianshu.com/u/6e525b929aac
 */
abstract class KotlinBaseActivity : BaseActivity() {
    override fun initBinding() {

    }

    override fun initData() {
    }

    override fun setView() {
    }

    fun initTopBar(title: String?) {
        rl_title.backgroundColor = ContextCompat.getColor(this, R.color.colorPrimary)
        back.onClick {
            finish()
        }
        tv_title.text = title
    }


    fun initTopBar(title: String?, right: String? = null, listener: View.OnClickListener? = null) {
        rl_title.backgroundColor = ContextCompat.getColor(this, R.color.colorPrimary)
        back.onClick {
            finish()
        }

        tv_title.text = title
        if (right != null) {
            tv_right.visibility = View.VISIBLE
            tv_right.text = right
            tv_right.onClick {
                listener?.onClick(tv_right)
            }
        }
    }

    fun initTopBar(title: String?, right: Int? = null, listener: View.OnClickListener? = null) {
        rl_title.backgroundColor = ContextCompat.getColor(this, R.color.colorPrimary)
        back.onClick {
            finish()
        }

        tv_title.text = title

        if (right != null) {
            iv_right.visibility = View.VISIBLE
            iv_right.setImageResource(right)
            iv_right.onClick {
                listener?.onClick(tv_right)
            }
        }
    }


}